Skip to content

Add client side navigation #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025
Merged

Add client side navigation #530

merged 3 commits into from
Jun 18, 2025

Conversation

peterp
Copy link
Member

@peterp peterp commented Jun 18, 2025

This adds the ability for us to initialize client-side navigation, also known as single-page apps.

Docs: https://pp-client-navigation.redwood-sdk-docs.pages.dev/guides/frontend/client-side-nav/

Copy link

cloudflare-workers-and-pages bot commented Jun 18, 2025

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1cd0e9e
Status: ✅  Deploy successful!
Preview URL: https://72ba7478.redwood-sdk-docs.pages.dev
Branch Preview URL: https://pp-client-navigation.redwood-sdk-docs.pages.dev

View logs

@peterp peterp requested a review from justinvdm June 18, 2025 14:28
1. Intercept the link click,
2. Push the new URL to the browser's history,
3. Fetch the new page's RSC payload from the server,
4. And hydrate it on the client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}

// Skip if download attribute
if (link.hasAttribute("download")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition says that it's such a little footnote that it doesn't really matter. It's the expected behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, woops, I didn't know its an actual standard attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#download :D

But I also don't know how I was thinking it could be non-standard 🤦

} = {
onNavigate: async function onNavigate() {
// @ts-expect-error
await globalThis.__rsc_callServer();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incredible how simple this is!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's pretty incredible.

Copy link
Collaborator

@justinvdm justinvdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: 🚀

@peterp
Copy link
Member Author

peterp commented Jun 18, 2025

At some point, I would like to get a hook on the fetch that has been called by call server because then I can actually implement some kind of preload functionality.

@peterp
Copy link
Member Author

peterp commented Jun 18, 2025

I just realized that if we push down a redirect response or an error response, we should probably not try and deal with that. We should just reload the browser at this point.

@peterp peterp merged commit a386cc5 into main Jun 18, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants